{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=742
  Verdict: Accepted
}
uses SysUtils, Math;
 
const
	p:int64=860243;
	x:int64=257;
 
type
	node = record
		v:int64;
		c:longint;
	end;
	ar=array of node;
 
var
	 i,n,h,ind,j:longint;
	 a:array[0..1000500] of ar;
	 k:int64;
 
function count:int64;
var j:longint; c,i:int64; f:boolean;
begin
i:=256;
result:=0;
while result=0 do begin
      c:=i;
      f:=true;
      for j:=2 to p-2 do begin
          c:=(c*i) mod p;
          if c=1 then begin
             f:=false;
             break;
          end;
      end;
      if f then result:=i;
      inc(i);
end;
end;
 
function hash(s:string):int64;
var
	i,ls:longint;
	c:int64;
begin
result:=0;
c:=1;
ls:=length(s);
for i:=1 to ls do begin
	c:=(c*x) mod p;
	inc(result,(ord(s[i])*c) mod p);
	result:=result mod p;
end;
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
for i:=1 to p do begin
	setlength(a[i],1);
	a[i][0].v:=0;
	a[i][0].c:=0;
end;
read(n);
for i:=1 to n do begin
	read(k);
	h:=hash(inttostr(k));
	ind:=0;
	for j:=1 to a[h][0].v do 
		if a[h][j].v=k then begin
			ind:=j;
			break;
		end;	
	if ind=0 then begin
		inc(a[h][0].v);
		setlength(a[h],a[h][0].v+1); 
		ind:=a[h][0].v;
		a[h][ind].v:=k;
		a[h][ind].c:=0;
	end;
	inc(a[h][ind].c);
end;
read(n);
for i:=1 to n do begin
	read(k);
	h:=hash(inttostr(k));
	ind:=0;
	for j:=1 to a[h][0].v do 
		if a[h][j].v=k then begin
			ind:=j;
			break;
		end;
	write(a[h][ind].c,' ');
end;
end.